<template>
	<jk-dialog
		v-model="showDialog"
		:title="`${ dataItem.deviceNumber || '' } / ${ dataItem.belongDate || '' } / ${ dataItem.shiftName || '' }-详情`"
		width="900px"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		:show-close-btn="true"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<!--<div class="flex-end-center margin-bottom-10">
			<jk-select v-model="searchParams.machine" placeholder="设备" class="search-bar-item-size2 item-gap"></jk-select>
			<jk-select v-model="searchParams.shiftId" placeholder="班次" class="search-bar-item-size2 item-gap"></jk-select>
			<jk-date-picker v-model="searchParams.dateTimeRange" type="datetimerange" start-placeholder="班次开始时间" end-placeholder="班次结束时间" class="item-gap"></jk-date-picker>
			<jk-search-button></jk-search-button>
		</div>-->
		<div ref="box1" class="flex-center margin-bottom-10">
			<el-radio-group v-model="comName">
				<el-radio-button label="chartView"><span class="el-icon-s-marketing item-gap"></span>图形</el-radio-button>
				<el-radio-button label="tableView"><span class="el-icon-c-scale-to-original item-gap"></span>二维表</el-radio-button>
			</el-radio-group>
		</div>
		<component
			:is="comName"
			:height="dialogTableHeight - 30"
			:chart-data="chartData"
		></component>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { spinShiftGetThousandIngotsPerHourTrend } from '../../../../api/statistic/spindleReports';
    import tableView from './components/table-view.vue';
    import chartView from './components/chart-view.vue';
    export default {
        name: 'MachineArchives',
        components: {
            tableView, chartView
        },
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataItem: {
                type: Object,
                default() {
                    return {
                        deviceNumber: '',
                        belongDate: '',
                        shiftName: ''
                    };
                }
            }
        },
        mixins: [calHeight],
        data() {
            return {
                comName: 'tableView',
                searchParams: {},
                showDialog: false,
                chartData: []
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
            },

            getDetailRequest() {
                if (!this.dataItem.spinShiftId) return false;
                return spinShiftGetThousandIngotsPerHourTrend({
                    spinShiftId: this.dataItem.spinShiftId
                }).then(res => {
                    if (res.data.status === 200) {
                        this.chartData = res.data.res || [];
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal && this.dataItem.spinShiftId) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
